package com.banyiyi.simple.pattern.observer;

/**
 * @ClassName WeatherData
 * @Description 天气预报平台
 * @Author yangwm
 * @Date 2023/2/15 11:18
 * @Version 1.0
 */
public class WeatherData extends Subject{

    // 天气预报平台 添加温度、湿度、PM2.5
    private float temperature;
    private float pressure;
    private float pm25;

    @Override
    public void add(Observer observer) {
        observers.add(observer);
    }

    @Override
    public void remove(Observer observer) {
        if(observers.contains(observer)){
            observers.remove(observer);
        }
    }

    @Override
    public void notifyObserver() {
        observers.forEach(observer -> observer.responce());
    }


    public void setData(float temperature, float pressure, float pm25){
        this.temperature = temperature;
        this.pressure = pressure;
        this.pm25 = pm25;
        System.out.println("当前温度为 " + this.temperature + " 摄氏度，湿度为 " + this.pressure + "%，PM2.5为 " + this.pm25);
        notifyObserver();
    }


}
